package co.edu.unal.bioingenium.kbmed.knowledge.mapping.vo;

import java.util.BitSet;

/**
 *
 * @author  Alejandro Riveros Cruz
 */
public class DescriptorScore implements Comparable<DescriptorScore> {

    /**
     * The total descriptor score [0,1]
     */
    private double totalScore;
    /**
     * The number of tokens in the descriptor
     */
    private short descriptorTokens;
    /**
     * The bitSet of the descriptor for a given sentence, 1 if the descriptor token appears in the bitset position
     */
    private BitSet bitSetKey;
    /**
     * Array with the detailed scores for a given sentence 
     */
    private double[] scores;

    private DescriptorScore() {
    }

    /**
     * @param:
     * @return:
     * @param senteceLength 
     */
    public DescriptorScore(int senteceLength) {
        totalScore = 0;
        scores = new double[senteceLength];
        bitSetKey = new BitSet(senteceLength);
    }

    /**
     * @param:
     * @return:
     * @return 
     */
    public double getTotalScore() {
        return totalScore;
    }

    /**
     * @param:
     * @return:
     * @param score 
     */
    public void setTotalScore(double score) {
        this.totalScore = score;
    }

    /**
     * 
     * @return
     */
    public double[] getScores() {
        return scores;
    }

    /**
     * 
     * @param wordSentencePosition
     * @param similarity
     */
    public void setScore(int wordSentencePosition, double similarity) {
        scores[wordSentencePosition] = similarity;
        bitSetKey.set(wordSentencePosition);
    }

    /**
     * 
     * @return
     */
    public int matches() {
        return bitSetKey.cardinality();
    }

    /**
     * 
     * @return
     */
    public short getDescriptorTokens() {
        return descriptorTokens;
    }

    /**
     * 
     * @param numTokens
     */
    public void setDescriptorTokens(short numTokens) {
        this.descriptorTokens = numTokens;
    }

    /**
     * 
     * @return
     */
    public BitSet getBitSetKey() {
        return bitSetKey;
    }

    @Override
    public int compareTo(DescriptorScore o) {
        if (this.totalScore > o.getTotalScore()) {
            return -1;
        } else {
            return 1;
        }
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("scores : ");
        for (int i = 0; i < scores.length; i++) {
            builder.append(scores[i]).append(" ");
        }
        builder.append("\t totalScore:").append(totalScore);
        return builder.toString();
    }
}
